﻿namespace Pna.InfoSource.Sbb
{
    using System;
    using System.Linq;

    using Pna.InfoSource.Sbb.JsonModels;
    using ServiceStack.ServiceClient.Web;

    /// <summary>
    /// The SBB info.
    /// </summary>
    public class SbbInfoSample
    {
        /// <summary>
        /// Samples the connection.
        /// </summary>
        public void SampleConnection()
        {
            var client = new JsonServiceClient("http://transport.opendata.ch/v1/");
            var res =
                client.Get(
                    new RequestConnectionInfo
                        {
                            From = "Goldiwil",
                            To = "Sulgen",
                            DateTime = new DateTime(2012, 11, 2, 8, 0, 0)
                        });

            var longest = res.Connections.OrderByDescending(con => con.DurationTimeSpan).First();
            var fastest = res.Connections.OrderBy(con => con.DurationTimeSpan).First();

            var diff = longest.DurationTimeSpan.Subtract(fastest.DurationTimeSpan);
        }
    }
}
